#!/usr/bin/env python
# -*- coding: latin-1 -*-
# -*- coding: cp1252 -*-


annadTup = (1, 5, 10, 50, 100, 500, 1000)
ag = {1: 'I', 5: 'V', 10: 'X', 50: 'L', 100: 'C', 500: 'D', 1000: 'M'}
ga = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
tala = input()
tala = int(tala)
tups = ("", tala)

def Giskun(tup):
	for x in range(len(annadTup)-1):
		if int(tup[1]) in range(annadTup[x], annadTup[x+1]):
			return (str(tup[0])+str(ag[annadTup[x]])), (int(tup[1])-int(annadTup[x]))
	print("Villa") # Þetta gerist en þá returnast ekkert, gerist bara fyrir tölur >= 1000

def Snyrting(strengur):
	strengur = strengur.replace('CCCC', 'CD')
	strengur = strengur.replace('XXXX', 'XL')
	strengur = strengur.replace('IIII', 'IV')
	return strengur

einhverListi = []
einhverListi.append(tups)
ind = 0
while einhverListi[ind][1] != 0:
	einhverListi.append(Giskun(einhverListi[ind]))
	ind += 1
Svar = Snyrting(einhverListi[ind][0])

print(Svar)

